<template>
  <!--<el-dialog title="添加店铺" :visible.sync="shopVisible">-->
  <el-dialog
    :title="'添加店铺'+$route.name"
    :visible="shopVisible"
    @update:visible="v=>$emit('update:shopVisible',false)"
  >
    <el-form>
      <el-form-item label="店铺名称:" label-width="120px">
        <el-input v-model="shopForm.shopName" autocomplete="off" style="width:200px"></el-input>
      </el-form-item>
      <el-form-item label="店铺类别" label-width="120px">
        <el-select v-model="shopForm.shopTypeId" placeholder="请选择">
          <el-option
            v-for="item in $store.state.shop.allShopTypeList"
            :key="item._id"
            :label="item.shopTypeName"
            :value="item._id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="店铺图片:" label-width="120px">
        <el-upload
          name="shopPic"
          :data="shopForm"
          :headers="{
            authorization:$store.state.admin.token
                 }"
          ref="upload"
          :on-success="success"
          :limit="1"
          :auto-upload="false"
          class="upload-demo"
          action="/api/shopList"
          list-type="picture"
        >
          <el-button size="small" type="primary">点击上传</el-button>
          <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
        </el-upload>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="$emit('update:shopVisible',false)">取 消</el-button>
      <el-button type="primary" @click="$refs.upload.submit()">提 交</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  components: {},
  props: {
    shopVisible: {
      type: Boolean,
      default: false
    },
    shopTypeId: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      shopForm: {
        shopName: "",
        shopTypeId: ""
      }
    };
  },
  watch: {},
  computed: {},
  methods: {
    success(res) {
      if (res.ok === 1) {
        this.$store.dispatch("getShopList");
        this.$emit("update:shopVisible", false);
        if (this.$route.name !== "shopList") {
          this.$router.history.push("/shopList");
        }
      } else {
        this.$message.error(res.msg);
      }
    }
  },
  created() {
    if (this.shopTypeId) {
      this.shopForm.shopTypeId = this.shopTypeId;
    }
    console.log(this.shopTypeId);
  },
  mounted() {}
};
</script>
<style lang="scss" scoped>
</style>